package Test.com;

import java.util.ArrayList;

/**
 * @author げっしょく
 * @date 2021/7/12
 */
public class test02 {
    /**
     1.创建一个ArrayList集合，用于存储一些字符串："abc","def","def","ghi","def","hij","jkol"
     2.遍历集合，统计集合中"def"字符串一共出现了多少个
	 3.将集合中的所有"def"字符串删除。打印删除后的集合元素
     */
    public static void main(String[] args) {
        //1.创建一个ArrayList集合，用于存储一些字符串："abc","def","def","ghi","def","hij","jkol""def"
        ArrayList<String> list = new ArrayList<>();
        list.add("abc");
        list.add("def");
        list.add("def");
        list.add("ghi");
        list.add("def");
        list.add("hij");
        list.add("jkol");
        list.add("def");
        int count = 0;
        //2.遍历集合，统计集合中"def"字符串一共出现了多少个
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            if("def".equals(s)){
                list.remove(i);
                i--;
                count++;
            }
        }
        //3.将集合中的所有"def"字符串删除。打印删除后的集合元素
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.println(s);
        }
        System.out.println("def在该集合中有"+count+"个");
    }
}
